package Clients;

import java.awt.Toolkit;

import javax.swing.*;
import Middle.*;
import DBAccess.*;

/**
 * Starts the Customer Client & Cashier client as a single application.
 * Good for testing the system using a single process and no RMI.
 * @author  Michael Alexander Smith
 * @version 2.0
 */

class Main
{
	//private static double hfScrX = Toolkit.getDefaultToolkit().getScreenSize().getWidth()/2;
	//private static double hfScrY = Toolkit.getDefaultToolkit().getScreenSize().getHeight()/2;
	private static double scrnW = Toolkit.getDefaultToolkit().getScreenSize().getWidth();
	private static double scrnH = Toolkit.getDefaultToolkit().getScreenSize().getHeight();
	private static double hfScrX = 0;
	private static double hfScrY = 0;
	private static int posX = 0;
	private static int posY = 0;	
	private static final int distX = 410;
	private static final int distY = 310;
	
  public static void main (String args[])
  {
    MiddleFactory mlf = new LocalMiddleFactory();  // Direct access
    displayCustomerGUI( mlf );
    displayCashierGUI( mlf );
    displayBackDoorGUI( mlf );
    displayPickGUI( mlf );             // 2 Pick GUI's
    //displayPickGUI( mlf );
    displayDisplayGUI( mlf );
    displayCollectionGUI( mlf );
  }

  public static void displayCustomerGUI(MiddleFactory mlf )
  {
    JFrame  window = new JFrame();
    
    window.setTitle( "Customer Client");
    window.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    //if(posX>=scrnW-410){
    	//posY+=distY;
    	//posX=0;
    //}else{
    	//posX+=distX;
    //}
    window.setLocation((int) hfScrX+posX, (int) hfScrY+posY);
    window.setResizable(false);
    new CustomerGUI( window, mlf );
  }
  public static void displayCashierGUI(MiddleFactory mlf )
  {
    JFrame  window = new JFrame();

    window.setTitle( "Cashier Client");
    window.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    if(posX>=scrnW-820){
    	posY+=distY;
    	posX=0;
    }else{
    	posX+=distX;
    }
    window.setLocation((int) hfScrX+posX, (int) hfScrY+posY);
    window.setResizable(false);
    new CashierGUI( window, mlf ); 
  }

  public static void displayBackDoorGUI(MiddleFactory mlf )
  {
    JFrame  window = new JFrame();

    window.setTitle( "BackDoor Client");
    window.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    if(posX>=scrnW-820){
    	posY+=distY;
    	posX=0;
    }else{
    	posX+=distX;
    }
    window.setLocation((int) hfScrX+posX, (int) hfScrY+posY);
    window.setResizable(false);
    new BackDoorGUI( window, mlf ); 
  }

  public static void displayPickGUI(MiddleFactory mlf )
  {
    JFrame  window = new JFrame();

    window.setTitle( "Pick Client");
    window.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    if(posX>=scrnW-820){
    	posY+=distY;
    	posX=0;
    }else{
    	posX+=distX;
    }
    window.setLocation((int) hfScrX+posX, (int) hfScrY+posY);
    window.setResizable(false);
    new PickGUI( window, mlf ); 
  }

  public static void displayDisplayGUI(MiddleFactory mlf )
  {
    JFrame  window = new JFrame();

    window.setTitle( "Display Client");
    window.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    
    window.setTitle( "Display Client");
    if(posX>=scrnW-820){
    	posY+=distY;
    	posX=0;
    }else{
    	posX+=distX;
    }
    window.setLocation((int) hfScrX+posX, (int) hfScrY+posY);
    window.setResizable(false);
    new DisplayGUI( window, mlf ); 
  }

  public static void displayCollectionGUI(MiddleFactory mlf )
  {
    JFrame  window = new JFrame();

    window.setTitle( "Collection Client");
    window.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    if(posX>=scrnW-820){
    	posY+=distY;
    	posX=0;
    }else{
    	posX+=distX;
    }
    window.setLocation((int) hfScrX+posX, (int) hfScrY+posY);
    window.setResizable(false);
    new CollectionGUI( window, mlf ); 
  }
  // Repeat for other clients
}
